import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
///测试事件的监听
class Test_Listener extends StatefulWidget {
  const Test_Listener({super.key});

  @override
  State<Test_Listener> createState() => _Test_ListenerState();
}

class _Test_ListenerState extends State<Test_Listener> {
  PointerEvent? _event;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text('TestName')),
        body: Column(children: [
          /// 正常测试监听widget
          Listener(
            child: Container(
              alignment: Alignment.center,
              color: Colors.blue,
              width: 300.0,
              height: 150.0,
              child: Text(
                '${_event?.localPosition ?? ''}',
                style: TextStyle(color: Colors.white),
              ),
            ),
            onPointerDown: (PointerDownEvent event) =>
                setState(() => _event = event),
            onPointerMove: (PointerMoveEvent event) =>
                setState(() => _event = event),
            onPointerUp: (PointerUpEvent event) =>
                setState(() => _event = event),
          ),
          const Text('吸收指针事件'),
          Listener(
            /// AbsorbPointer吸收事件，本身响应事件
            child: AbsorbPointer(
              child: Listener(
                child: Container(
                  color: Colors.blue,
                  width: 200.0,
                  height: 100.0,
                ),
                ///不触发
                onPointerDown: (event) => print("in"),
              ),
            ),
            ///触发
            onPointerDown: (event) => print("up"),
          ),
          const Text('忽略指针事件'),
          Listener(
            ///IgnorePointer 本身不接受，里外不执行
            child: IgnorePointer(
              child: Listener(
                child: Container(
                  color: Colors.red,
                  width: 200.0,
                  height: 100.0,
                ),
                onPointerDown: (event) => print("in"),
              ),
            ),
            onPointerDown: (event) => print("up"),
          ),
          Listener(
            /**
             * 1.命中测试由内向外触发
             */
            child: Listener(
              child: Container(
                color: Colors.brown,
                width: 200.0,
                height: 100.0,
              ),
              ///里边优先响应
              onPointerDown: (event) => print("in"),
            ),
            ///外边其次响应
            onPointerDown: (event) => print("up"),
          ),
          // 存在冲突问题待解决 手势冲突问题
          GestureDetector(
            child: GestureDetector(
              child: Container(
                child: Text("GestureDetector"),
              ),
              onTap: () {
                print('JtTag:in');
              },
            ),
            onTap: () {
              print('JtTag:out');
            },
          )
        ]));
  }
}
